import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:get/get.dart';

class MySumController extends SumController {
  RxInt sumIndex = 1.obs;
  final RxList<String> sumList = ['BLUETOOTH', 'LINE RCA', '2-CH', '4-CH'].obs;
  late final RxList<GroupModel> groupList;
  @override
  void onInit() {
    super.onInit();
    final list = globalController.rxModel.value.ch_list;
    groupList = List.generate((list.length / 2).toInt(), (index) {
      final model = GroupModel(ch1: list[2 * index], ch2: list[2 * index + 1]);
      model.select = model.ch1!.select && model.ch2!.select;
      return model;
    }).obs;
  }

  void chooseSum(int index) {
    sumIndex.value = index;
    switch (sumList[index]) {
      case 'BLUETOOTH':
        globalController.updateUSBorRCA(type: SourceType.bt);
        break;
      case 'LINE RCA':
        globalController.updateUSBorRCA(type: SourceType.rca);
        break;
      case '2-CH':
        globalController.updateSum(type: SumType.sum2CH);
        break;
      case '4-CH':
        globalController.updateSum(type: SumType.sum4CH);
        break;
      default:
    }
  }
}
